pull: Ensure we always process queue only from main thread
authorColin Walters <walters@verbum.org>
Fri, 17 Jun 2016 02:16:27 +0000 (22:16 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Fri, 17 Jun 2016 18:19:23 +0000 (18:19 +0000)
commit535033a4f01f772e696ad2201b34403203b98bea
tree6263018557d95e712335f276f1c1c651ff1af99e
parentd262fc2e0ff80472594bd931971512971ff4af04
pull: Ensure we always process queue only from main thread

I was easily reproducing a hang on pulls with thousands of requests on
current git master.  The initial symptom seemed to be that there are
multiple code paths where we don't invoke
`session_thread_process_pending_queue()`.  We really need to do
that any time we remove something from the outstanding queue,
to ensure it gets filled again.

A further issue is that we were tying the lifecycle of the pending
object to the `GTask`, but the task could be unref'd from the main
thread (via a `GSource` on the main thread), and that introduced
threadsafety issues, because the hash table and other data suddenly
could be concurrently modified.

Both of these need to be fixed together.  First, we introduce
`Arc<Pending>`, and ensure that both the main and worker threads hold
references.

Second, we ensure that we re-process the queue *immediately* whenever
a task is done, inside the worker thread, rather than doing it
incidentally via an unref.  This architecture is quite similar to what
the outside pull code is doing.

Closes: #350
Approved by: jlebon
src/libostree/ostree-fetcher.c